#include <vector>
using namespace std;
int maxProfit(vector<int> &prices) {
  int len = prices.size();
  int maxValue = 0;
  int minPrice = prices[0];
  for (int i = 0; i < len; i++) {
    if (prices[i] < minPrice) {
      minPrice = prices[i];
      continue;
    }
    if (prices[i] - minPrice > maxValue)
      maxValue = prices[i] - minPrice;
  }
  return maxValue;
}